<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>post请求语法</title>
		<script src="js/axios.js"></script>
	</head>
	<body>
		<h1>post提交</h1>
		<script>
			axios.defaults.baseURL="http://localhost:8080/axios"
			
			/**
			 * 需求:一般业务新增时,采用post提交
			 * URL: http://localhost:8080/axios/saveUser
			 * axios.post(url地址,js对象)
			 * 		.then(回调函数!!!)
			 */
			//写法1:利用对象传参提交数据
			let user1 = {id:100,name:"tomcat",age:18,sex:"女"}
			axios.post("/saveUser",user1)
				 .then(promise => {
					 console.log(promise.data)
				 })
			
			//写法2:利用restFul结构实现,
			let url5 = `http://localhost:8080/axios/user/${user1.id}/${user1.name}/${user1.age}/${user1.sex}`
			axios.post(url5)
				 .then(promise => {
					 console.log(promise.data)
				 })
				 
			/**
			 * 业务需求: 实现数据更新操作
			 * 			修改id=3的数据 name="张三" age=18
			 * URL:http://localhost:8080/axios/user
			 * 类型: put
			 * 写法1:利用对象传参提交数据
			 * 写法2:利用restFul结构实现
			 */
			//写法1:利用对象传参提交数据
			let user2 = {id:3,name:"张三",age:18}
			axios.put("/updateUser",user2)
				 .then(promise => {
					 console.log(promise.data)
				 })
				
			//写法2:利用restFul结构实现,
			let url3 = `http://localhost:8080/axios/user/${user2.name}/${user2.age}/${user2.id}`
			axios.put(url3)
				 .then(promise => {
					 console.log(promise.data)
				 })
				 
			//pose 与 put 提交语法相同
			//get 与 delete 提交语法相同
		</script>
	</body>
</html>
